package com.atguigu.tree;

public class OrderTreeDemo {
    public static void main(String[] args) {
        int arr[] = {1,2,3,4,5,6,7};

        OrderTree orderTree = new OrderTree(arr);
        orderTree.preOrder(0);
    }
}

class OrderTree{
    int arr[];

    public OrderTree(int arr[]){
        this.arr = arr;
    }

    //前序遍历
    public void preOrder(int index){
        if (index < arr.length){
            System.out.println(arr[index]);
        }

        if (2*index+1 < arr.length){
            preOrder(2*index+1);
        }

        if (2*index+2 < arr.length){
            preOrder(2*index+2);
        }
    }
}
